var HOST = 'jieyan.xyitech.com';  
// var PORT = 10888;
var PORT = 10885;
const net = require('net');
const client = net.createConnection({port: PORT, host: HOST}, () => {
  //'connect' listener
  console.log('connected to server!');
  setInterval(function () {
    // var body = new Buffer(10);
    // body.writeInt32LE(6, 0)
    // body.writeUInt8(254, 4);
    // body.writeInt32LE(30, 5);
    // body.writeUInt8(2, 9);
    // // console.log("body", body)
    // client.write(body);

    //tower
    //[151,1,1,0,240,1]
    //[152,1,1490161439,0,0,0,0,0]
    var body = new Buffer(13);
    body.writeInt32LE(9, 0)
    body.writeUInt8(151, 4);
    body.writeUInt32LE(2147483649, 5);
    body.writeUInt8(1, 9);
    body.writeUInt8(0, 10);
    body.writeUInt8(240, 11);
    body.writeUInt8(1, 12);
    // console.log("body", body)
    client.write(body);
    body.writeUInt32LE(2147483649 + 44, 5);
    client.write(body);
    body.writeUInt32LE(2147483649 + 45, 5);
    client.write(body);
    
   // var body = new Buffer(9);
   //  body.writeUInt32LE(5, 0)
   //  body.writeUInt8(7, 4);
   //  body.writeUInt32LE(40, 5);
   //  // console.log("body", body)
   //  client.write(body);
    // var body = new Buffer(31);
    // body.writeInt32LE(27, 0)
    // body.writeUInt8(108, 4);
    // body.writeUInt8(29, 5);
    // body.writeUInt8(1, 6);
    // body.writeUInt8(0, 7);
    // body.writeUInt16LE(1, 8);
    // body.writeUInt8(1, 10);
    // body.writeInt32LE(1123, 11)
    // body.writeInt32LE(2123, 15)
    // body.writeInt32LE(3123, 19)
    // body.writeInt32LE(4123, 23)
    // body.writeInt32LE(800, 27)
    // // console.log("body", body)
    // client.write(body);
    // client.write("asdasda")
    // client.write('10{"fid":30}');
  }, 1000)
  
  // client.end();
});
client.on('data', (data) => {
  console.log("receiving", data);
  // console.log("receiving", data.readUInt32LE(0));
  // console.log("receiving", data.readUInt8(4));
  // console.log("receiving", data.readUInt32LE(5));
  // console.log("receiving", data.readUInt32LE(9));
  
  // client.end();
});
client.on('end', () => {
  console.log('disconnected from server');
});


require('net').createServer(function(sock) {

    sock.on('data', function(data) {
        console.log(data)
    });
    sock.on('error', function (err) {
        console.log('ERROR: ', err);
    });
    sock.on('close', function(err) {
        console.log('CLOSED: ')
        
    });
}).listen(9999, '0.0.0.0');